package com.doit.day01;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.settings.Settings;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class ShowIndex {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));

        //创建一个get请求
        GetIndexRequest request = new GetIndexRequest("java");

        //获取响应
        GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);

        //获取别名
        Map<String, List<AliasMetaData>> aliases = response.getAliases();
        //从响应结果中获取mapping的相关信息
        Map<String, MappingMetaData> mappings = response.getMappings();
        //从响应结果中获取详细信息
        Map<String, Settings> settings = response.getSettings();

        System.out.println("aliases:"+aliases);
        System.out.println("mappings:"+mappings);
        System.out.println("settings:"+settings);

    }
}
